home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / window.cp < prev   
Encoding:
Text File  |  2000-09-28  |  5.1 KB  |  214 lines

  1. /*
  2.     File:        Window.cp
  3.  
  4.     Contains:    TWindow is a Window wrapper class that handles most of the basic window functionality.
  5.                   Window.cp contains the TWindow member functions.
  6.  
  7.     Written by:     
  8.  
  9.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. #ifndef _WINDOW_
  25. #include "Window.h"
  26. #endif 
  27.  
  28.  
  29. // _________________________________________________________________________________________________________ //
  30. // TWindow class member function implementations.
  31. // CONSTRUCTORS AND DESTRUCTORS
  32. #pragma segment Window
  33. TWindow::TWindow()
  34. {
  35.     this->Initialize();                            // initialize fields to known values    
  36.  
  37.     // Create Window.
  38.     TEnvironment myEnvironment;                    // check out our environment if Color QD is present
  39.  
  40.     if (myEnvironment.HasColorQD())
  41.     {
  42.         fWindow = ::NewCWindow(NULL, &fRect, fWindowTitle, true, noGrowDocProc, (WindowPtr) - 1L, true, 0L);
  43.         fColorWindow = true;
  44.     }
  45.     else
  46.         fWindow = ::NewWindow(NULL, &fRect, fWindowTitle, true, noGrowDocProc, (WindowPtr) - 1L, true, 0L);
  47.  
  48.     ASSERT(fWindow != NULL, "\pProblems with TWindow::TWindow, NewWindow");
  49.     fWindowRecord = (WindowPeek)fWindow;        // get ptr to the real window record        
  50. }
  51.  
  52.  
  53. #pragma segment Window
  54. TWindow::TWindow(short windowID)
  55. // Create window based on resource ID.
  56. {
  57.     fColorWindow = false;                        // can't assume anything…
  58.  
  59.     // Create Window.
  60.     TEnvironment myEnvironment;                    // check out our environment if Color QD is present
  61.  
  62.     if (myEnvironment.HasColorQD())
  63.     {
  64.         fWindow = ::GetNewCWindow(windowID, NULL, (WindowPtr) - 1);
  65.         fColorWindow = true;
  66.     }
  67.     else
  68.         fWindow = ::GetNewCWindow(windowID, NULL, (WindowPtr) - 1);
  69.     ASSERT(fWindow != NULL, "\pProblems with TWindow::TWindow(ResID), GetNewWindow");
  70.  
  71.     fWindowRecord = (WindowPeek)fWindow;        // get ptr to the real window record        
  72. }
  73.  
  74.  
  75. #pragma segment Window
  76. TWindow::~TWindow()
  77. // Default destructor -- get rid of the window memory allocations.
  78. {
  79.     ::DisposeWindow(fWindow);                    // dispose our WindowPtr
  80. }
  81.  
  82.  
  83. #pragma segment Window
  84. void TWindow::Initialize()
  85. // Initialize the window to a known state (title, position).
  86. {
  87.     Pstrcpy(fWindowTitle, "\pUntitled");        // set default window title
  88.     fRect.top = TWindow::kTop;                    // set default window rect
  89.     fRect.left = TWindow::kLeft;
  90.     fRect.bottom = TWindow::kBottom;
  91.     fRect.right = TWindow::kRight;
  92.  
  93.     fColorWindow = false;                        // can't assume anything…
  94. }
  95.  
  96.  
  97. // MAIN INTERFACE
  98. #pragma segment Window
  99. void TWindow::Draw()
  100. // Draw is an implementation dependent function, you need to override this one
  101. // and create your own drawing routines.
  102. {
  103. }
  104.  
  105.  
  106. #pragma segment Window
  107. void TWindow::DoClick()
  108. // DoClick is an implementation dependent function, you need to override this one
  109. // and create your own mouse click routines.
  110. {
  111. }
  112.  
  113.  
  114. #pragma segment Window
  115. void TWindow::Show()
  116. // Make window visible.
  117. {
  118.     ::ShowWindow(fWindow);
  119. }
  120.  
  121.  
  122. #pragma segment Window
  123. void TWindow::Hide()
  124. // Make window invisible.
  125. {
  126.     ::HideWindow(fWindow);
  127. }
  128.  
  129.  
  130. // GET/SET FUNCTIONS
  131. #pragma segment Window
  132. WindowPtr TWindow::GetWindowPtr() const
  133. // Get the actual windowPtr record.
  134. {
  135.     return fWindow;
  136. }
  137.  
  138.  
  139. #pragma segment Window
  140. void TWindow::SetTitle(const Str255* title)
  141. // Set window title.
  142. {
  143.     Str255 oldTitle;
  144.  
  145.     // Get old title, if still the same, don't bother changing it (less flicker)
  146.     ::GetWTitle(fWindow, oldTitle);
  147.  
  148.     if (!CompareStr255(&oldTitle, title))
  149.         ::SetWTitle(fWindow, *title);
  150. }
  151.  
  152.  
  153. #pragma segment Window
  154. void TWindow::GetTitle(Str255* result) const
  155. // Get window title.
  156. {
  157.     if (fWindow)                                // we have a valid window?
  158.         ::GetWTitle(fWindow, *result);
  159.     else
  160.         Pstrcpy(*result, "\p");                    // copy in an empty string
  161. }
  162.  
  163.  
  164. #pragma segment Window
  165. Rect TWindow::GetExtent() const
  166. // Get the internal Rect of window.
  167. {
  168.     return fWindow->portRect;
  169. }
  170.  
  171.  
  172. #pragma segment Window
  173. Rect TWindow::GetFrame() const
  174. // Get the frame Rect of window.
  175. {
  176.     Rect frame;
  177.     
  178.     frame.left = -1;
  179.     frame.top = -1;
  180.  
  181.     // Include one pixel for the the frame itself!
  182.     frame.right = fWindow->portRect.right - fWindow->portRect.left + 1;
  183.     frame.bottom = fWindow->portRect.bottom - fWindow->portRect.top + 1;
  184.  
  185.     return frame;
  186. }
  187.  
  188.  
  189. #pragma segment Window
  190. Boolean TWindow::Contains(Point test) const
  191. // Check if point is inside window.
  192. {
  193.     return (::PtInRgn(test, fWindowRecord->contRgn));
  194. }
  195.  
  196.  
  197. #pragma segment Window
  198. Boolean TWindow::IsColorWindow() const
  199. // Return true/false if window is a color grafport based one.
  200. {
  201.     return fColorWindow;
  202. }
  203.  
  204.  
  205. // _________________________________________________________________________________________________________ //
  206.  
  207.  
  208. /*    Change History (most recent last):
  209.   No        Init.    Date        Comment
  210.   1            khs        11/7/92        New file
  211.   2            khs        1/7/93        Cleanup
  212. */
  213.  
  214.